<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class C_account extends CI_Controller {
	function __construct(){
		parent::__construct();
	}

	/**
	 * Index Page for this controller.
	 */
	function create_pagination($total_page, $page_active, $pos){
		$pagination = "";
		$pagination .= '<button type="button" onClick="show_productbypage(0)" id="product_pagefirst'. $pos .'" class="button_pagination" title="First"><<</button>';
		if($page_active !== 0){ 
			$pagination .= '<button type="button" onClick="show_productbypage(';
			$pagination .= $page_active - 1;
			$pagination .= ')" id="product_pageprev'. $pos .'" class="button_pagination" title="Preview"><</button>';
		} else { 
			$pagination .= '<button type="button" onClick="show_productbypage(0)" id="product_pageprev'. $pos .'" class="button_pagination" title="Preview"><</button>'; 
		}
		for($i=0;$i<$total_page;$i++){
			if($page_active == $i){
				$pagination .= '<button type="button" onClick="show_productbypage('. $i .')" id="product_page'. $i . $pos .'" class="active_page" title="Next">';
				$pagination .= $i + 1;
				$pagination .= '</button>';
			}else{
				$pagination .= '<button type="button" onClick="show_productbypage('. $i .')" id="product_page'. $i . $pos .'" class="button_pagination" title="Next">';
				$pagination .= $i + 1;
				$pagination .= '</button>';
			}
		}
		if($page_active == $total_page - 1){ 
			$pagination .= '<button type="button" onClick="show_productbypage(';
			$pagination .= $page_active;
			$pagination .= ')" id="product_pagenext'. $pos .'" class="button_pagination" title="Next">></button>';
		} else { 
			$pagination .= '<button type="button" onClick="show_productbypage(';
			$pagination .= $page_active + 1;
			$pagination .= ')" id="product_pagenext'. $pos .'" class="button_pagination" title="Next">></button>';
		}
		$pagination .= '<button type="button" onClick="show_productbypage(';
		$pagination .= $total_page - 1;
		$pagination .= ')" id="product_pagelast'. $pos .'" class="button_pagination" title="Last">>></button>';
		return $pagination;
	}
	public function index(){
		$this->load->view('main/v_account');
	}
	function v_userproduct(){
		$sort = isset($_GET['sort']) ? @$_GET['sort'] : 'produk_nama';
		$start = isset($_GET['start']) ? @$_GET['start'] : '0';
		$show_number = isset($_GET['shownumber']) ? @$_GET['shownumber'] : '9';
		if($sort == "name"){
			$sort = "produk_nama";
		}else if($sort == "price"){
			$sort = "produk_harga";
		}
		$end = $start + $show_number;
		$user_id = $this->session->userdata('DX_user_id');
		$data['product_havebought'] = $this->m_public_function->product_havebought_list($user_id, $sort, $start, $end);
		$num_rows = $this->m_public_function->count_producthavebought($user_id);
		$total_page = ceil($num_rows / $show_number);
		$page_active = $start / $show_number;
		
		$data['pagination_top'] = $this->create_pagination($total_page, $page_active, "top");
		$data['pagination_bottom'] = $this->create_pagination($total_page, $page_active, "bottom");
		$this->load->vars($data);
		$this->load->view('main/v_userproduct');
	}
	function download(){
		$product_id = trim(@$_POST['pid']);
		$result = $this->m_public_function->get_produk_url($product_id);
		echo $result;
	}
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */